<?php require_once('Connections/RecursosHumanos.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO evaluacion (ID_EVALUACION, DESCRIPCION) VALUES (%s, %s)",
                       GetSQLValueString($_POST['ID_EVALUACION'], "text"),
                       GetSQLValueString($_POST['DESCRIPCION'], "text"));

  mysql_select_db($database_RecursosHumanos, $RecursosHumanos);
  $Result1 = mysql_query($insertSQL, $RecursosHumanos) or die(mysql_error());

  $insertGoTo = "CrearEvaluacion.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

$maxRows_Eval = 10;
$pageNum_Eval = 0;
if (isset($_GET['pageNum_Eval'])) {
  $pageNum_Eval = $_GET['pageNum_Eval'];
}
$startRow_Eval = $pageNum_Eval * $maxRows_Eval;

mysql_select_db($database_RecursosHumanos, $RecursosHumanos);
$query_Eval = "SELECT * FROM evaluacion ORDER BY evaluacion.ID_EVALUACION";
$query_limit_Eval = sprintf("%s LIMIT %d, %d", $query_Eval, $startRow_Eval, $maxRows_Eval);
$Eval = mysql_query($query_limit_Eval, $RecursosHumanos) or die(mysql_error());
$row_Eval = mysql_fetch_assoc($Eval);

if (isset($_GET['totalRows_Eval'])) {
  $totalRows_Eval = $_GET['totalRows_Eval'];
} else {
  $all_Eval = mysql_query($query_Eval);
  $totalRows_Eval = mysql_num_rows($all_Eval);
}
$totalPages_Eval = ceil($totalRows_Eval/$maxRows_Eval)-1;

$queryString_Eval = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_Eval") == false && 
        stristr($param, "totalRows_Eval") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_Eval = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_Eval = sprintf("&totalRows_Eval=%d%s", $totalRows_Eval, $queryString_Eval);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
<style type="text/css">
<!--
body {
	margin-left: 2cm;
	margin-top: 1cm;
}
.Estilo2 {font-size: 12px}
-->
</style></head>

<body>
<p><a href="home.html">REGRESAR</a></p>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
  <table align="left">
    <tr valign="baseline">
      <td nowrap align="right"><div align="left">Id evaluacion :</div></td>
      <td><input type="text" name="ID_EVALUACION" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"><div align="left">Descripcion:</div></td>
      <td><input type="text" name="DESCRIPCION" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"><div align="left"></div></td>
      <td><input type="submit" value="Insertar registro"></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1">
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<table border="1" align="left">
  <tr>
    <td width="137">Id evaluacion </td>
    <td width="396">Descripcion</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><span class="Estilo2"><?php echo $row_Eval['ID_EVALUACION']; ?></span></td>
      <td><span class="Estilo2"><a href="ModificarEvaluacion.php?EVA_MOD=<?php echo $row_Eval['ID_EVALUACION']; ?>"><?php echo $row_Eval['DESCRIPCION']; ?></a></span></td>
    </tr>
    <?php } while ($row_Eval = mysql_fetch_assoc($Eval)); ?>
</table>
<p>&nbsp;</p>
<p>
<p>
<table border="0" width="50%">
  <tr>
    <td width="23%" align="center"><?php if ($pageNum_Eval > 0) { // Show if not first page ?>
          <a href="<?php printf("%s?pageNum_Eval=%d%s", $currentPage, 0, $queryString_Eval); ?>">Primero</a>
          <?php } // Show if not first page ?>
    </td>
    <td width="31%" align="center"><?php if ($pageNum_Eval > 0) { // Show if not first page ?>
          <a href="<?php printf("%s?pageNum_Eval=%d%s", $currentPage, max(0, $pageNum_Eval - 1), $queryString_Eval); ?>">Anterior</a>
          <?php } // Show if not first page ?>
    </td>
    <td width="23%" align="center"><?php if ($pageNum_Eval < $totalPages_Eval) { // Show if not last page ?>
          <a href="<?php printf("%s?pageNum_Eval=%d%s", $currentPage, min($totalPages_Eval, $pageNum_Eval + 1), $queryString_Eval); ?>">Siguiente</a>
          <?php } // Show if not last page ?>
    </td>
    <td width="23%" align="center"><?php if ($pageNum_Eval < $totalPages_Eval) { // Show if not last page ?>
          <a href="<?php printf("%s?pageNum_Eval=%d%s", $currentPage, $totalPages_Eval, $queryString_Eval); ?>">&Uacute;ltimo</a>
          <?php } // Show if not last page ?>
    </td>
  </tr>
</table>
</p>
</body>
</html>
<?php
mysql_free_result($Eval);
?>
